﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using dhDataAcess.produceLinq;
using dhDataAcess.dataAcess.produceDataSetTableAdapters;
using dhDataAcess.dataAcess;

namespace dhDataAcess.produceDAL
{
  public  class pdfpjlbDAL
    {
        string  tableName = "pdfpjlb";
        private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public pdfpjlbDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction ;
            conn = _conn;
        }
        /// <summary>
        /// 插入胚带发胚记录表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int pdfpjlbInsert(pdfpjlbModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
           // string insertstr = "insert into pbomMaster (mark,updateUser,updateDate,createUser,createDate,checkDate,spr,zbr,awgight,bweight,machineType,custNum,pname) values(@mark,@updateUser,@updateDate,@createUser,@createDate,@checkDate,@spr,@zbr,@awgight,@bweight,@machineType,@custNum,@pname)";
            string insertstr = baseBLL.dTableColumnRead.insertSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                        new SqlParameter ("@mark",row.mark ),
                                        new SqlParameter ("@updateUser",row .updateUser ),
                                        new SqlParameter ("@updateDate",row .updateDate ),
                                        new SqlParameter ("@createDate",row .createDate ),
                                        new SqlParameter ("@createUser",row .createUser ),
                                        new SqlParameter ("@billStatus",row .billStatus ),
                                        new SqlParameter ("@dyestatus",row .dyestatus ),
                                        new SqlParameter ("@dyeDate",row .dyeDate ),
                                        new SqlParameter ("@qty",row .qty ),
                                        new SqlParameter ("@sendDate",row .sendDate ),
                                        new SqlParameter ("@unit",row .unit ),
                                        new SqlParameter ("@sendQty",row .sendQty ),
                                        new SqlParameter ("@pname",row .pname ),
                                        new SqlParameter ("@orderDetailNo",row .orderDetailNo ),
                                         new SqlParameter ("@piaoranDate",row .piaoranDate  ),
                                        new SqlParameter ("@machineNo",row .machineNo  ),
                                        new SqlParameter ("@pdopen",row .pdopen  ),
                                        new SqlParameter ("@productopen",row .productopen),
                                        new SqlParameter ("@sendqtyL",row .sendqtyL ),
                                        new SqlParameter ("@billoNo",row .billoNo),
                                          new SqlParameter ("@yujiqty",row .yujiqty),
                                        new SqlParameter ("@pdweight",row .pdweight),
                                        new SqlParameter ("@sendqtyJ",row .sendqtyJ),
                                        new SqlParameter ("@pdfw",row .pdfw ),
                                        new SqlParameter ("@pdenough",row .pdenough)



                                    };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = insertstr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 插入胚带入库主表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int pdfpjlbInsertII(produceDataSet.pdfpjlbDataTable pdfpjlbTable)
        {
            DataTable dt = new DataTable();

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            // string insertstr = "insert into pbomMaster (mark,updateUser,updateDate,createUser,createDate,checkDate,spr,zbr,awgight,bweight,machineType,custNum,pname) values(@mark,@updateUser,@updateDate,@createUser,@createDate,@checkDate,@spr,@zbr,@awgight,@bweight,@machineType,@custNum,@pname)";
            string insertstr = "pdfpjlbDataUpdate";
            SqlParameter par = new SqlParameter("@pdfpjlbMasterData", pdfpjlbTable);
            par.SqlDbType = SqlDbType.Structured;
            par.TypeName = "pdfpjlbTableType";
            cmd.Parameters.Add(par);
            cmd.CommandText = insertstr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 更新胚带发胚记录表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int pdfpjlbUpdate(pdfpjlbModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
          string updatestr = baseBLL.dTableColumnRead.updateSqlStr(tableName).ToString();
            //string updatestr="update pdfpjlb set mark=@mark,updateUser=@updateUser,updateDate=@updateDate,createDate=@createDate,createUser=@createUser,billStatus=@billStatus,dyestatus=@dyestatus,dyeDate=@dyeDate,recordid=@recordid where recordid=@recordid";


            SqlParameter[] para = {
                                        
                                         new SqlParameter ("@mark",row.mark ),
                                        new SqlParameter ("@updateUser",row .updateUser ),
                                        new SqlParameter ("@updateDate",row .updateDate ),
                                        new SqlParameter ("@createDate",row .createDate ),
                                        new SqlParameter ("@createUser",row .createUser ),
                                        new SqlParameter ("@billStatus",row .billStatus ),
                                        new SqlParameter ("@dyestatus",row .dyestatus ),
                                        new SqlParameter ("@dyeDate",row .dyeDate ),
                                        new SqlParameter ("@qty",row .qty ),
                                        new SqlParameter ("@sendDate",row .sendDate ),
                                        new SqlParameter ("@unit",row .unit ),
                                        new SqlParameter ("@sendQty",row .sendQty ),
                                        new SqlParameter ("@pname",row .pname ),
                                        new SqlParameter ("@orderDetailNo",row .orderDetailNo ),
                                         new SqlParameter ("@piaoranDate",row .piaoranDate  ),
                                        new SqlParameter ("@machineNo",row .machineNo  ),
                                        new SqlParameter ("@pdopen",row .pdopen  ),
                                        new SqlParameter ("@productopen",row .productopen),
                                        new SqlParameter ("@sendqtyL",row .sendqtyL ),
                                        new SqlParameter ("@yujiqty",row .yujiqty),
                                        new SqlParameter ("@pdweight",row .pdweight),
                                        new SqlParameter ("@sendqtyJ",row .sendqtyJ),
                                          new SqlParameter ("@pdfw",row .pdfw ),
                                        new SqlParameter ("@pdenough",row .pdenough)
                                     
                                    };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updatestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行胚带发胚记录表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int pdfpjlbDel(string recordid)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deletestr = baseBLL.dTableColumnRead.delSqlStr (tableName).ToString();
            SqlParameter[] para = {
                                     
                                        new SqlParameter ("@recordid",recordid )
                                   };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = deletestr ;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行胚带入库主表更新库存数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int pdfpjlbDelII(string billNo)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter[] para = {
                                     
                                        new SqlParameter ("@billNo",billNo )
                                   };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = "pdfpdel";
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
    }
}
